<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        //浅拷贝
        function copyObj1(target){
            let newObj = {};
            for(const key in target){
                newObj[key] = target[key];
            }
            return newObj ;
        }

        //深拷贝
        function copyObj2(target){
            if (typeof target ==='object') {
                let newObj = {};
                for(const key in target){
                   newObj[key] = target[key];
                }
                return newObj
            }else{
                return target
            }
            
        }



        const user = {
            name:'小明',
            age:'18',
            array:[1,2,3,4,5],
            f1: function(){
                console.log('f1函数');
            }
        }

        console.log(copyObj2(user));


    </script>
    
</body>
</html>